import Taro from '@tarojs/taro'
import { get, READ1000_USER_INFO, set } from '../globalData';

export default function getLoginInfo() {
  const userInfo =  get(READ1000_USER_INFO)
  const userCach = Taro.getStorageSync(READ1000_USER_INFO)
  if(
    (!userInfo && !userCach)
    || (!userInfo && userCach.timeStamp && (new Date().getTime() - userCach.timeStamp > 5 * 24 * 60 * 60 * 1000))
  ) {
    console.log('跳转登录...')
    Taro.redirectTo({
      url: '/pages/login/index'
    })
  }else if (!userInfo && userCach.timeStamp) {
    set(READ1000_USER_INFO, userCach)
    return userCach
  } else if (userInfo) {
    return userInfo
  }
}
